package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysCheckBoxConvert;
import net.learn.system.convert.SysCheckBoxDetailConvert;
import net.learn.system.dao.SysCheckBoxDetailDao;
import net.learn.system.entity.SysCheckBoxDetailEntity;
import net.learn.system.entity.SysCheckBoxEntity;
import net.learn.system.query.SysCheckBoxDetailQuery;
import net.learn.system.query.SysCheckBoxQuery;
import net.learn.system.service.SysCheckBoxDetailService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysCheckBoxDetailVO;
import net.learn.system.vo.SysCheckBoxVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 李立志
 * @since 2022-04-01
 */
@Service
public class SysCheckBoxDetailServiceImpl extends BaseServiceImpl<SysCheckBoxDetailDao, SysCheckBoxDetailEntity> implements SysCheckBoxDetailService {

    @Override
    public Boolean addCheckBoxDetail(SysCheckBoxDetailVO vo){
        SysCheckBoxDetailEntity entity = SysCheckBoxDetailConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        return baseMapper.insert(entity)>0;
    }
    @Override
    public Boolean updateCheckBoxDetail(SysCheckBoxDetailVO vo){
        SysCheckBoxDetailEntity entity = SysCheckBoxDetailConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }
    @Override
    public List<SysCheckBoxDetailVO> qryCheckBoxDetailList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<SysCheckBoxDetailVO> getCheckBoxDetailArray() {
        return baseMapper.getCheckBoxDetailArray();
    }
    @Override
    public List<SysCheckBoxDetailVO> qryPaperCheckBoxList(SysCheckBoxDetailQuery qry) {
        return baseMapper.qryPaperCheckBoxList(qry);
    }
    @Override
    public List<SysCheckBoxDetailVO> qryPaperCheckBoxCondition(SysCheckBoxDetailQuery qry) {
        return baseMapper.qryPaperCheckBoxCondition(qry);
    }
    @Override
    public PageResult<SysCheckBoxDetailVO> qryCheckBoxDetailListPage(SysCheckBoxDetailQuery query) {
        IPage<SysCheckBoxDetailEntity> page = baseMapper.qryCheckBoxDetailListPage(getPage(query), query);

        return new PageResult<>(SysCheckBoxDetailConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
